# 作者: 陈其志 
# 2025年02月25日10时20分29秒 
# 2716847110@qq.com

import re

if __name__ == '__main__':
    # 匹配变量名是否合法：变量名只能包含字母、数字、下划线，且不能以数字开头
    names = ['name1', '_name2', '3_name', '__name__']
    for name in names:
        ret = re.match(r'[a-zA-Z_]\w*', name)
        if ret:
            print(f'{name} is valid')
        else:
            print(f'{name} is invalid')
    print('-' * 50)
    # 匹配0-99
    ret = re.match(r'[1-9]?[0-9]', '9')
    print(ret.group())
    ret = re.match(r'[1-9]?\d', '33')
    print(ret.group())
    ret = re.match(r'[1-9]?\d', '09')
    print(ret.group())
    et = re.match(r'[1-9]?\d$', '0')
    print(ret.group())

    # 匹配邮箱地址
    ret = re.match(r"[a-zA-Z0-9_]*@[a-zA-Z0-9]{0,3}.com$", "abc@123.com")
    print(ret.group())

    email_list = ["xiaoWang@163.com", "xiaoWang@163.comheihei", ".com.xiaowang@qq.com"]
    for email in email_list:
        ret = re.match(r"[a-zA-Z0-9_]{5,20}@[a-zA-Z0-9]{0,3}.com$", email)
        if ret:
            print(f"{ret.group()}是合法地址")
        else:
            print(f"{email}不是合法地址")
